package com.nulldev.util.data.Arrays.arrays.util;

import java.util.ListIterator;

import com.nulldev.util.JVM.JVM;
import com.nulldev.util.VariableAPI.ArrayUtils;
import com.nulldev.util.concurrency.threadIt.v4.emapi.ExecutorManager;
import com.nulldev.util.data.Arrays.arrays.FastArrayList;

public class FALTests {
	public static void main(String[] args) {
		final FastArrayList<String> e = new FastArrayList<String>();
		e.add("Hello");
		e.add("World!");
		e.add("testing");
		JVM.println("index[0]: " + e.get(0));
		JVM.println("index[1]: " + e.get(1));
		JVM.println("index[2]: " + e.get(2));
		JVM.println("set(2): " + e.set(2, "tested!"));
		JVM.println("Iterator<>: ");
		e.iterator().forEachRemaining((f) -> {
			JVM.println(f);
		});
		JVM.print("toArray: ");
		JVM.println(e.toArray());
		JVM.print("toArray(String[]): ");
		JVM.println(e.toArray(new String[e.size()]));
		JVM.println("remove(2): " + e.remove(2));
		try {
			JVM.println("get(2): " + e.get(2));
		} catch (IndexOutOfBoundsException _ignored) {
			JVM.println("get(2): IndexOutOfBoundsException");
		}
		e.clear();
		JVM.print("clear: ");
		JVM.println(e.toArray());
		JVM.println("multi-thread-add:");
		ExecutorManager.get().await(ExecutorManager.globalAsyncSubmit(() -> {
			e.add("value 1");
			e.add("value 2");
			return true;
		}), ExecutorManager.globalAsyncSubmit(() -> {
			e.add("value 3");
			e.add("value 4");
			return true;
		}), ExecutorManager.globalAsyncSubmit(() -> {
			e.add("value 5");
			e.add("value 6");
			return true;
		}));
		JVM.print("current value(s): ");
		JVM.println(e.toArray());
		JVM.println("Iterator<>: ");
		e.iterator().forEachRemaining((f) -> {
			JVM.println(f);
		});
		JVM.println("parallelStream: ");
		e.parallelStream().forEach((f) -> {
			JVM.println(f);
		});
		JVM.println("listIterator(0):");
		final ListIterator<String> s = e.listIterator(0);
		while (s.hasNext()) {
			JVM.println(s.next());
		}
		e.remove(5);
		e.remove(1);
		ArrayUtils.printLln(e.toArray(new String[4]));
	}
}
